using AForge.Video;
using AForge.Video.DirectShow;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace SilverSea.Video.Tools
{
	public class frmViewCamera : Form
	{
		private IContainer icontainer_0;
		private PictureBox pictureBox1;
		private Timer timer_0;
		private Button btnVideoCaptureDevideSetting;
		private CheckBox chkFitImage;
		private Label lblVideoSize;
		private Button btnAdjustVideo;
        private IContainer components;
		private Camera camera_0;
		public Camera CurrentCamera
		{
			get
			{
				return this.camera_0;
			}
			set
			{
				this.camera_0 = value;
			}
		}
		public frmViewCamera()
		{
            ((ISupportInitialize)this.pictureBox1).BeginInit();
            ((ISupportInitialize)this.pictureBox1).EndInit();
			this.InitializeComponent();
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmViewCamera));
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.timer_0 = new System.Windows.Forms.Timer(this.components);
            this.btnVideoCaptureDevideSetting = new System.Windows.Forms.Button();
            this.chkFitImage = new System.Windows.Forms.CheckBox();
            this.lblVideoSize = new System.Windows.Forms.Label();
            this.btnAdjustVideo = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // pictureBox1
            // 
            resources.ApplyResources(this.pictureBox1, "pictureBox1");
            this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.TabStop = false;
            // 
            // timer_0
            // 
            this.timer_0.Enabled = true;
            this.timer_0.Tick += new System.EventHandler(this.timer_0_Tick);
            // 
            // btnVideoCaptureDevideSetting
            // 
            resources.ApplyResources(this.btnVideoCaptureDevideSetting, "btnVideoCaptureDevideSetting");
            this.btnVideoCaptureDevideSetting.Name = "btnVideoCaptureDevideSetting";
            this.btnVideoCaptureDevideSetting.UseVisualStyleBackColor = true;
            this.btnVideoCaptureDevideSetting.Click += new System.EventHandler(this.btnVideoCaptureDevideSetting_Click);
            // 
            // chkFitImage
            // 
            resources.ApplyResources(this.chkFitImage, "chkFitImage");
            this.chkFitImage.Name = "chkFitImage";
            this.chkFitImage.UseVisualStyleBackColor = true;
            this.chkFitImage.CheckedChanged += new System.EventHandler(this.chkFitImage_CheckedChanged);
            // 
            // lblVideoSize
            // 
            resources.ApplyResources(this.lblVideoSize, "lblVideoSize");
            this.lblVideoSize.Name = "lblVideoSize";
            // 
            // btnAdjustVideo
            // 
            resources.ApplyResources(this.btnAdjustVideo, "btnAdjustVideo");
            this.btnAdjustVideo.Name = "btnAdjustVideo";
            this.btnAdjustVideo.UseVisualStyleBackColor = true;
            this.btnAdjustVideo.Click += new System.EventHandler(this.btnAdjustVideo_Click);
            // 
            // frmViewCamera
            // 
            resources.ApplyResources(this, "$this");
            this.Controls.Add(this.btnAdjustVideo);
            this.Controls.Add(this.lblVideoSize);
            this.Controls.Add(this.chkFitImage);
            this.Controls.Add(this.btnVideoCaptureDevideSetting);
            this.Controls.Add(this.pictureBox1);
            this.Name = "frmViewCamera";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmViewCamera_FormClosing);
            this.Load += new System.EventHandler(this.frmViewCamera_Load);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		private void timer_0_Tick(object sender, EventArgs e)
		{
			if (this.camera_0 != null)
			{
				System.Drawing.Bitmap currentVideoFrame = this.camera_0.GetCurrentVideoFrame();
				this.pictureBox1.Image = currentVideoFrame;
				if (currentVideoFrame != null)
				{
					this.lblVideoSize.Text = string.Concat(new object[]
					{
						"Video Size: ",
						currentVideoFrame.Width,
						"x",
						currentVideoFrame.Height
					});
					return;
				}
				this.lblVideoSize.Text = string.Empty;
			}
		}
		private void btnVideoCaptureDevideSetting_Click(object sender, EventArgs e)
		{
			try
			{
				IVideoSource videoSource = this.camera_0.videoSourcePlayer.VideoSource;
				if (videoSource is VideoCaptureDevice)
				{
					((VideoCaptureDevice)videoSource).DisplayPropertyPage(base.Handle);
				}
			}
			catch (NotSupportedException)
			{
				MessageBox.Show("The video source does not support configuration property page.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
			}
		}
		private void frmViewCamera_Load(object sender, EventArgs e)
		{
			this.btnVideoCaptureDevideSetting.Enabled = false;
			this.chkFitImage.Enabled = false;
			this.btnAdjustVideo.Enabled = false;
			if (this.camera_0 != null)
			{
				if (this.camera_0.CameraType == CameraType.VideoCaptureDevice)
				{
					this.btnVideoCaptureDevideSetting.Enabled = true;
					IVideoSource videoSource = this.camera_0.videoSourcePlayer.VideoSource;
					if (videoSource is VLC_VideoCaptureDevice)
					{
						this.btnAdjustVideo.Enabled = true;
					}
				}
				this.chkFitImage.Enabled = true;
			}
		}
		private void chkFitImage_CheckedChanged(object sender, EventArgs e)
		{
			if (this.chkFitImage.Checked)
			{
				this.pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
				return;
			}
			this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
		}
		private void btnAdjustVideo_Click(object sender, EventArgs e)
		{
			VLC_VideoCaptureDevice vLC_VideoCaptureDevice = (VLC_VideoCaptureDevice)this.camera_0.videoSourcePlayer.VideoSource;
			if (vLC_VideoCaptureDevice != null)
			{
				vLC_VideoCaptureDevice.EnableAdjustFilter = true;
				frmAdjustFilter frmAdjustFilter = new frmAdjustFilter();
				frmAdjustFilter.Brightness = vLC_VideoCaptureDevice.Brightness;
				frmAdjustFilter.Contrast = vLC_VideoCaptureDevice.Contrast;
				frmAdjustFilter.Gamma = vLC_VideoCaptureDevice.Contrast;
				frmAdjustFilter.BrightnessAdjust += new BrightnessAdjustEventHandler(this.method_0);
				frmAdjustFilter.ContrastAdjust += new ContrastAdjustEventHandler(this.method_1);
				frmAdjustFilter.GammaAdjust += new GammaAdjustEventHandler(this.method_2);
				frmAdjustFilter.ShowDialog();
			}
		}
		private void method_0(float float_0)
		{
			VLC_VideoCaptureDevice vLC_VideoCaptureDevice = (VLC_VideoCaptureDevice)this.camera_0.videoSourcePlayer.VideoSource;
			if (vLC_VideoCaptureDevice != null)
			{
				vLC_VideoCaptureDevice.Brightness = float_0;
			}
		}
		private void method_1(float float_0)
		{
			VLC_VideoCaptureDevice vLC_VideoCaptureDevice = (VLC_VideoCaptureDevice)this.camera_0.videoSourcePlayer.VideoSource;
			if (vLC_VideoCaptureDevice != null)
			{
				vLC_VideoCaptureDevice.Contrast = float_0;
			}
		}
		private void method_2(float float_0)
		{
			VLC_VideoCaptureDevice vLC_VideoCaptureDevice = (VLC_VideoCaptureDevice)this.camera_0.videoSourcePlayer.VideoSource;
			if (vLC_VideoCaptureDevice != null)
			{
				vLC_VideoCaptureDevice.Gamma = float_0;
			}
		}
		private void frmViewCamera_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.timer_0.Stop();
		}
	}
}
